package info.qingshui.browser.hk.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;

// 数据操作的基础类，作为数据操作的内嵌子类
public class ObjectDBHelper extends SQLiteOpenHelper {

	public ObjectDBHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
		Log.d(this.getClass().getSimpleName(), "ObjectDBHelper "); 
	}

	public void onCreate(SQLiteDatabase db) {
		String sql = "create table if not exists " + ObjectDB.OBJECT_TABLE_NAME
		+ " ( " + ObjectDB.CLASS_NAME_COL_NAME + " varchar PRIMARY KEY, "
		+ ObjectDB.CLASS_DATA_COL_NAME + " blob);";
		try {
			db.execSQL(sql);
		} catch (Exception ex) {
			Log.e ( this.getClass().getSimpleName(), "onCreate",ex); 
		}
		Log.d(this.getClass().getSimpleName(), "onCreate "); 
	}

	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
		Log.d(this.getClass().getSimpleName(), "onOpen "); 
	}
	
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.d(this.getClass().getSimpleName(), "onUpgrade "); 
		String sql = "drop table " + ObjectDB.OBJECT_TABLE_NAME;
		try {
			db.execSQL(sql);
		} catch (Exception ex) {
			Log.e ( this.getClass().getSimpleName(), "onUpgrade",ex); 
		}
		Log.d(this.getClass().getSimpleName(), "onUpgrade "); 
		onCreate( db);
	}
	
	
	
	

} 
